package com.jwell.panrank.model

import com.jwell.driverapp.tools.BaseSubscriber
import com.jwell.panrank.application.App
import com.jwell.panrank.contract.PreRegisterPlaneContract
import com.jwell.panrank.entity.ReleaseCodeBean
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * Created by 76577 on 2018/4/11.
 * 预登记验收计划
 */
class PreRegisterPlaneModel : PreRegisterPlaneContract.Model, BaseModel() {

    override fun getContractListByProName(id: String, baseSubscriber: BaseSubscriber) {
        if (App.DEBUG) println("根据货物名查询合同" + id)
        val map = mutableMapOf("id" to id)
        getApiStore().getContractListByProName(map)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }

    override fun createFuelPlan(requestData: RequestData, baseSubscriber: BaseSubscriber) {
        if (App.DEBUG) println("预登记验收计划" + requestData.toString())
        getApiStore().createFuelPlan(requestData)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(baseSubscriber)
    }

    //    planType (integer, optional): 计划类型 1、按合同号 2、按品名 = ['1', '2'],
//    measurementMethod (integer, optional): 计量方式 1、先重后空 2、先空后重 3、标证出皮 4、只称重车 5、只称空车 = ['1', '2', '3', '4', '5'],
//    planCarCount (integer, optional): 计划车数 ,
//    materialName (string, optional): 物质名称 ,
    //materialCode :品名代码
//    forwardingUnit (string, optional): 发货单位 ,
//    receivingUnit (string, optional): 收货单位 ,
//    planDate (string, optional): 供应时间-开始 ,
//    planDateEnd (string, optional): 供应时间-结束 ,
//    fuelPlanDetail (Array[Logistics.Application.QueuingSystems.Dto.ForExportWaybills.CreateFuelPlanDetailDto], optional): 计划详情 ,
//    id (integer, optional)
//advanceDay提前发布天数
    data class RequestData(var planType: Int? = null,
                           var measurementMethod: Int? = null,
                           var planCarCount: Int? = null,
                           var materialName: String? = null,
                           var materialCode: String? = null,
                           var forwardingUnit: String? = null,
                           var receivingUnit: String? = null,
                           var planDate: String? = null,
                           var planDateEnd: String? = null,
                           var fuelPlanDetail: List<DispatchInfo>? = null,
                           var id: Int? = null,
                           var advanceDay: Int? = null,
                           var isFixedPoint: Boolean? = false,
                           var fixedPointList: List<ReleaseCodeBean>? = null)

    //    appointCarCount (integer, optional): 指定车数 ,
//    mtrlOrderNo (string, optional): 合同号 ,
//    mtrlDescr (string, optional): 原燃料品名中文名称 ,
//    supplierName (string, optional): 供应商名称 ,
//    supplierId (integer, optional): 供应商id ,
    // isRobbing是否允许抢单，默认可以
    //materialCode品名代码名
//    id (integer, optional)
    data class DispatchInfo(var appointCarCount: Int? = null,
                            var mtrlOrderNo: String? = null,
                            var mtrlDescr: String? = null,
                            var materialCode: String? = null,
                            var supplierName: String? = null,
                            var supplierId: Int? = null,
                            var isRobbing: Boolean = true,
                            var id: Int? = null)
}